home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 326-350 / disk_329 / cpu / c / cpu.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  3KB  |  121 lines

  1. /*
  2.  
  3. CPU.c - program to write current CPUs in use to stdout
  4.  
  5. Ethan Dicks
  6. based upon WhatCPU by Dave Haynie
  7.  
  8. Version 2.1
  9. (c) 26-Feb-1990
  10.  
  11. This program is *not* in the public domain, but may be freely
  12. redistributed on the condition that it is not sold, nor used in any
  13. commercial or shareware package without the express written permission
  14. of the author.  This program may be included in a freely redistributable
  15. library, including, but not limited to the Fred Fish library collection.
  16. In other words, selling this program is right out, but giving it away is
  17. encouraged.
  18.  
  19. This program is an example of a standalone C module.  As of March 1989,
  20. one of the discussions on comp.sys.amiga has been regarding writing C
  21. without linking in startup code, such as AStartup.obj or c.o, and without
  22. linking in libraries, such as Amiga.lib.  This program is one example.  It
  23. is, however, bizarre, due to several shortcuts to shrink the size.  There
  24. have been many odd techniques used to cut corners, including assumptions
  25. about the content of the output, strange char array manipulation, and
  26. unusual register defines.  While the program could be clearer, it probably
  27. can't be made smaller.  The purpose of this program is not to be a good
  28. example, but, rather, to be an example of TIGHT C code.
  29.  
  30. COMPILATION INSTRUCTIONS:
  31.  
  32. This code has been tested under Lattice 5.04, but will probably compile
  33. under Lattice 4.x as well.
  34.  
  35. To compile, either use LMK and the provided Makefile, or use the commands:
  36.  
  37. lc -b -r -v -y CPU.c
  38. blink CPU.o to CPU SC SD ND
  39. */
  40.  
  41. #include <exec/types.h>
  42. #include <exec/execbase.h>
  43. #include <libraries/dos.h>
  44. #include <proto/exec.h>
  45. #include <proto/dos.h>
  46. /* This is all there is */
  47.  
  48.  
  49. /* Define the processor type strings */
  50. char    banner[] = "System Configuration: 680";
  51. char    id_68000[] = "00";
  52. char    id_68010[] = "10";
  53. char    id_68020[] = "20";
  54.  
  55. char    id_68881[] = "68881";
  56.  
  57. char    crlf[]    = "\n";
  58.  
  59. /* Here goes nuthin... */
  60. void _main()
  61. {
  62.  
  63. /* set up Intuition/AmigaDOS structure pointers */
  64.    struct DOSBase *DOSBase;
  65.    struct ExecBase **SysBase;
  66.    register struct ExecBase *ExecBase;
  67.  
  68. /* define other variables as registers, to save space */
  69.    register int attnflag;    /* processor type bits from ExecBase struct */
  70.    register ULONG stdout;    /* file handle of stdout */
  71.    register char *proc;        /* pointer to processor type string */
  72.  
  73. /* Set up the ExecBase pointer manually, since we don't link with anybody */
  74.    SysBase = (struct ExecBase **) (4L);    
  75.    ExecBase = *SysBase;
  76.  
  77. /* Open the DOS library, since there is no one to do it for us */
  78.    DOSBase = (struct DOSBase *)OpenLibrary(DOSNAME, 0);
  79.  
  80. /* Get the stdout filehandle */
  81.    stdout = Output();
  82.  
  83. /* Start printing */
  84.    Write(stdout, banner, sizeof(banner));
  85.  
  86. /* Only read the ExecBase structure once, to save space */
  87.    attnflag = ExecBase -> AttnFlags;
  88.  
  89.    if (attnflag & AFF_68020)
  90.    {
  91.     proc = id_68020;    /* point to string "20" */
  92.    }
  93.    else
  94.    {
  95.     if (attnflag & AFF_68010)
  96.     {
  97.     proc = id_68010;    /* point to string "10" */
  98.     }
  99.     else
  100.     {
  101.     proc = id_68000;    /* point to string "00" */
  102.     }
  103.    }
  104.  
  105. /* Write out the processor type string - always 2 chars */
  106.    Write(stdout, proc, 2);
  107.  
  108.    /* check for math co-processor */
  109.    if (attnflag & AFF_68881)
  110.    {
  111.     Write(stdout, id_68881, sizeof(id_68881));
  112.    }
  113.  
  114.    /* terminate the line */
  115.    Write(stdout, crlf, sizeof(crlf));
  116.  
  117. /* Clean up and go home */
  118.    (void) CloseLibrary(DOSBase);
  119.  
  120. }
  121.